/**************************************************************************
 * Name         : twidtabs.h
 * Author       : James McCarthy
 * Created      : 14/11/2006
 *
 * Copyright    : 2003-2008 by Imagination Technologies Limited.
 *              : All rights reserved. No part of this software, either
 *              : material or conceptual may be copied or distributed,
 *              : transmitted, transcribed, stored in a retrieval system or
 *              : translated into any human or computer language in any form
 *              : by any means,electronic, mechanical, manual or otherwise,
 *              : or disclosed to third parties without the express written
 *              : permission of Imagination Technologies Limited, 
 *              : Home Park Estate, Kings Langley, Hertfordshire,
 *              : WD4 8LZ, U.K.
 *
 * Platform     : ANSI
 *
 * $Log: twidtabs.h $
 **************************************************************************/
#ifndef _TWIDTABS_
#define _TWIDTABS_

#define SUB_TABLE_SIZE      (1024)

/* Gets twiddled address from UV coordinates */
#define GET_SQUARE_OFFSET(U,V) ui32SqrLookupTable[(IMG_UINT32)((U)/SUB_TABLE_SIZE)][(IMG_UINT32)((V)/SUB_TABLE_SIZE)]
#define GET_TWIDDLED_ADDRESS(U,V) (((ui32SubLookupTable[(IMG_UINT32)((U)%SUB_TABLE_SIZE)]<<1) \
        | ui32SubLookupTable[(IMG_UINT32)((V)%SUB_TABLE_SIZE)]) \
        + GET_SQUARE_OFFSET(U,V))

/* Sub sqare lookuptable (for textures > 1024x1024 ) */
static const IMG_UINT32 ui32SqrLookupTable[2][2] =
{
        {0x000000, 0x100000},
        {0x200000, 0x300000}
};

/* Static lookup table */
static const IMG_UINT32 ui32SubLookupTable[SUB_TABLE_SIZE] =
{
0x0,  0x1,  0x4,  0x5,  
0x10,  0x11,  0x14,  0x15,  
0x40,  0x41,  0x44,  0x45,  
0x50,  0x51,  0x54,  0x55,  
0x100,  0x101,  0x104,  0x105,  
0x110,  0x111,  0x114,  0x115,  
0x140,  0x141,  0x144,  0x145,  
0x150,  0x151,  0x154,  0x155,  
0x400,  0x401,  0x404,  0x405,  
0x410,  0x411,  0x414,  0x415,  
0x440,  0x441,  0x444,  0x445,  
0x450,  0x451,  0x454,  0x455,  
0x500,  0x501,  0x504,  0x505,  
0x510,  0x511,  0x514,  0x515,  
0x540,  0x541,  0x544,  0x545,  
0x550,  0x551,  0x554,  0x555,  
0x1000,  0x1001,  0x1004,  0x1005,  
0x1010,  0x1011,  0x1014,  0x1015,  
0x1040,  0x1041,  0x1044,  0x1045,  
0x1050,  0x1051,  0x1054,  0x1055,  
0x1100,  0x1101,  0x1104,  0x1105,  
0x1110,  0x1111,  0x1114,  0x1115,  
0x1140,  0x1141,  0x1144,  0x1145,  
0x1150,  0x1151,  0x1154,  0x1155,  
0x1400,  0x1401,  0x1404,  0x1405,  
0x1410,  0x1411,  0x1414,  0x1415,  
0x1440,  0x1441,  0x1444,  0x1445,  
0x1450,  0x1451,  0x1454,  0x1455,  
0x1500,  0x1501,  0x1504,  0x1505,  
0x1510,  0x1511,  0x1514,  0x1515,  
0x1540,  0x1541,  0x1544,  0x1545,  
0x1550,  0x1551,  0x1554,  0x1555,  
0x4000,  0x4001,  0x4004,  0x4005,  
0x4010,  0x4011,  0x4014,  0x4015,  
0x4040,  0x4041,  0x4044,  0x4045,  
0x4050,  0x4051,  0x4054,  0x4055,  
0x4100,  0x4101,  0x4104,  0x4105,  
0x4110,  0x4111,  0x4114,  0x4115,  
0x4140,  0x4141,  0x4144,  0x4145,  
0x4150,  0x4151,  0x4154,  0x4155,  
0x4400,  0x4401,  0x4404,  0x4405,  
0x4410,  0x4411,  0x4414,  0x4415,  
0x4440,  0x4441,  0x4444,  0x4445,  
0x4450,  0x4451,  0x4454,  0x4455,  
0x4500,  0x4501,  0x4504,  0x4505,  
0x4510,  0x4511,  0x4514,  0x4515,  
0x4540,  0x4541,  0x4544,  0x4545,  
0x4550,  0x4551,  0x4554,  0x4555,  
0x5000,  0x5001,  0x5004,  0x5005,  
0x5010,  0x5011,  0x5014,  0x5015,  
0x5040,  0x5041,  0x5044,  0x5045,  
0x5050,  0x5051,  0x5054,  0x5055,  
0x5100,  0x5101,  0x5104,  0x5105,  
0x5110,  0x5111,  0x5114,  0x5115,  
0x5140,  0x5141,  0x5144,  0x5145,  
0x5150,  0x5151,  0x5154,  0x5155,  
0x5400,  0x5401,  0x5404,  0x5405,  
0x5410,  0x5411,  0x5414,  0x5415,  
0x5440,  0x5441,  0x5444,  0x5445,  
0x5450,  0x5451,  0x5454,  0x5455,  
0x5500,  0x5501,  0x5504,  0x5505,  
0x5510,  0x5511,  0x5514,  0x5515,  
0x5540,  0x5541,  0x5544,  0x5545,  
0x5550,  0x5551,  0x5554,  0x5555,  
0x10000,  0x10001,  0x10004,  0x10005,  
0x10010,  0x10011,  0x10014,  0x10015,  
0x10040,  0x10041,  0x10044,  0x10045,  
0x10050,  0x10051,  0x10054,  0x10055,  
0x10100,  0x10101,  0x10104,  0x10105,  
0x10110,  0x10111,  0x10114,  0x10115,  
0x10140,  0x10141,  0x10144,  0x10145,  
0x10150,  0x10151,  0x10154,  0x10155,  
0x10400,  0x10401,  0x10404,  0x10405,  
0x10410,  0x10411,  0x10414,  0x10415,  
0x10440,  0x10441,  0x10444,  0x10445,  
0x10450,  0x10451,  0x10454,  0x10455,  
0x10500,  0x10501,  0x10504,  0x10505,  
0x10510,  0x10511,  0x10514,  0x10515,  
0x10540,  0x10541,  0x10544,  0x10545,  
0x10550,  0x10551,  0x10554,  0x10555,  
0x11000,  0x11001,  0x11004,  0x11005,  
0x11010,  0x11011,  0x11014,  0x11015,  
0x11040,  0x11041,  0x11044,  0x11045,  
0x11050,  0x11051,  0x11054,  0x11055,  
0x11100,  0x11101,  0x11104,  0x11105,  
0x11110,  0x11111,  0x11114,  0x11115,  
0x11140,  0x11141,  0x11144,  0x11145,  
0x11150,  0x11151,  0x11154,  0x11155,  
0x11400,  0x11401,  0x11404,  0x11405,  
0x11410,  0x11411,  0x11414,  0x11415,  
0x11440,  0x11441,  0x11444,  0x11445,  
0x11450,  0x11451,  0x11454,  0x11455,  
0x11500,  0x11501,  0x11504,  0x11505,  
0x11510,  0x11511,  0x11514,  0x11515,  
0x11540,  0x11541,  0x11544,  0x11545,  
0x11550,  0x11551,  0x11554,  0x11555,  
0x14000,  0x14001,  0x14004,  0x14005,  
0x14010,  0x14011,  0x14014,  0x14015,  
0x14040,  0x14041,  0x14044,  0x14045,  
0x14050,  0x14051,  0x14054,  0x14055,  
0x14100,  0x14101,  0x14104,  0x14105,  
0x14110,  0x14111,  0x14114,  0x14115,  
0x14140,  0x14141,  0x14144,  0x14145,  
0x14150,  0x14151,  0x14154,  0x14155,  
0x14400,  0x14401,  0x14404,  0x14405,  
0x14410,  0x14411,  0x14414,  0x14415,  
0x14440,  0x14441,  0x14444,  0x14445,  
0x14450,  0x14451,  0x14454,  0x14455,  
0x14500,  0x14501,  0x14504,  0x14505,  
0x14510,  0x14511,  0x14514,  0x14515,  
0x14540,  0x14541,  0x14544,  0x14545,  
0x14550,  0x14551,  0x14554,  0x14555,  
0x15000,  0x15001,  0x15004,  0x15005,  
0x15010,  0x15011,  0x15014,  0x15015,  
0x15040,  0x15041,  0x15044,  0x15045,  
0x15050,  0x15051,  0x15054,  0x15055,  
0x15100,  0x15101,  0x15104,  0x15105,  
0x15110,  0x15111,  0x15114,  0x15115,  
0x15140,  0x15141,  0x15144,  0x15145,  
0x15150,  0x15151,  0x15154,  0x15155,  
0x15400,  0x15401,  0x15404,  0x15405,  
0x15410,  0x15411,  0x15414,  0x15415,  
0x15440,  0x15441,  0x15444,  0x15445,  
0x15450,  0x15451,  0x15454,  0x15455,  
0x15500,  0x15501,  0x15504,  0x15505,  
0x15510,  0x15511,  0x15514,  0x15515,  
0x15540,  0x15541,  0x15544,  0x15545,  
0x15550,  0x15551,  0x15554,  0x15555,  
0x40000,  0x40001,  0x40004,  0x40005,  
0x40010,  0x40011,  0x40014,  0x40015,  
0x40040,  0x40041,  0x40044,  0x40045,  
0x40050,  0x40051,  0x40054,  0x40055,  
0x40100,  0x40101,  0x40104,  0x40105,  
0x40110,  0x40111,  0x40114,  0x40115,  
0x40140,  0x40141,  0x40144,  0x40145,  
0x40150,  0x40151,  0x40154,  0x40155,  
0x40400,  0x40401,  0x40404,  0x40405,  
0x40410,  0x40411,  0x40414,  0x40415,  
0x40440,  0x40441,  0x40444,  0x40445,  
0x40450,  0x40451,  0x40454,  0x40455,  
0x40500,  0x40501,  0x40504,  0x40505,  
0x40510,  0x40511,  0x40514,  0x40515,  
0x40540,  0x40541,  0x40544,  0x40545,  
0x40550,  0x40551,  0x40554,  0x40555,  
0x41000,  0x41001,  0x41004,  0x41005,  
0x41010,  0x41011,  0x41014,  0x41015,  
0x41040,  0x41041,  0x41044,  0x41045,  
0x41050,  0x41051,  0x41054,  0x41055,  
0x41100,  0x41101,  0x41104,  0x41105,  
0x41110,  0x41111,  0x41114,  0x41115,  
0x41140,  0x41141,  0x41144,  0x41145,  
0x41150,  0x41151,  0x41154,  0x41155,  
0x41400,  0x41401,  0x41404,  0x41405,  
0x41410,  0x41411,  0x41414,  0x41415,  
0x41440,  0x41441,  0x41444,  0x41445,  
0x41450,  0x41451,  0x41454,  0x41455,  
0x41500,  0x41501,  0x41504,  0x41505,  
0x41510,  0x41511,  0x41514,  0x41515,  
0x41540,  0x41541,  0x41544,  0x41545,  
0x41550,  0x41551,  0x41554,  0x41555,  
0x44000,  0x44001,  0x44004,  0x44005,  
0x44010,  0x44011,  0x44014,  0x44015,  
0x44040,  0x44041,  0x44044,  0x44045,  
0x44050,  0x44051,  0x44054,  0x44055,  
0x44100,  0x44101,  0x44104,  0x44105,  
0x44110,  0x44111,  0x44114,  0x44115,  
0x44140,  0x44141,  0x44144,  0x44145,  
0x44150,  0x44151,  0x44154,  0x44155,  
0x44400,  0x44401,  0x44404,  0x44405,  
0x44410,  0x44411,  0x44414,  0x44415,  
0x44440,  0x44441,  0x44444,  0x44445,  
0x44450,  0x44451,  0x44454,  0x44455,  
0x44500,  0x44501,  0x44504,  0x44505,  
0x44510,  0x44511,  0x44514,  0x44515,  
0x44540,  0x44541,  0x44544,  0x44545,  
0x44550,  0x44551,  0x44554,  0x44555,  
0x45000,  0x45001,  0x45004,  0x45005,  
0x45010,  0x45011,  0x45014,  0x45015,  
0x45040,  0x45041,  0x45044,  0x45045,  
0x45050,  0x45051,  0x45054,  0x45055,  
0x45100,  0x45101,  0x45104,  0x45105,  
0x45110,  0x45111,  0x45114,  0x45115,  
0x45140,  0x45141,  0x45144,  0x45145,  
0x45150,  0x45151,  0x45154,  0x45155,  
0x45400,  0x45401,  0x45404,  0x45405,  
0x45410,  0x45411,  0x45414,  0x45415,  
0x45440,  0x45441,  0x45444,  0x45445,  
0x45450,  0x45451,  0x45454,  0x45455,  
0x45500,  0x45501,  0x45504,  0x45505,  
0x45510,  0x45511,  0x45514,  0x45515,  
0x45540,  0x45541,  0x45544,  0x45545,  
0x45550,  0x45551,  0x45554,  0x45555,  
0x50000,  0x50001,  0x50004,  0x50005,  
0x50010,  0x50011,  0x50014,  0x50015,  
0x50040,  0x50041,  0x50044,  0x50045,  
0x50050,  0x50051,  0x50054,  0x50055,  
0x50100,  0x50101,  0x50104,  0x50105,  
0x50110,  0x50111,  0x50114,  0x50115,  
0x50140,  0x50141,  0x50144,  0x50145,  
0x50150,  0x50151,  0x50154,  0x50155,  
0x50400,  0x50401,  0x50404,  0x50405,  
0x50410,  0x50411,  0x50414,  0x50415,  
0x50440,  0x50441,  0x50444,  0x50445,  
0x50450,  0x50451,  0x50454,  0x50455,  
0x50500,  0x50501,  0x50504,  0x50505,  
0x50510,  0x50511,  0x50514,  0x50515,  
0x50540,  0x50541,  0x50544,  0x50545,  
0x50550,  0x50551,  0x50554,  0x50555,  
0x51000,  0x51001,  0x51004,  0x51005,  
0x51010,  0x51011,  0x51014,  0x51015,  
0x51040,  0x51041,  0x51044,  0x51045,  
0x51050,  0x51051,  0x51054,  0x51055,  
0x51100,  0x51101,  0x51104,  0x51105,  
0x51110,  0x51111,  0x51114,  0x51115,  
0x51140,  0x51141,  0x51144,  0x51145,  
0x51150,  0x51151,  0x51154,  0x51155,  
0x51400,  0x51401,  0x51404,  0x51405,  
0x51410,  0x51411,  0x51414,  0x51415,  
0x51440,  0x51441,  0x51444,  0x51445,  
0x51450,  0x51451,  0x51454,  0x51455,  
0x51500,  0x51501,  0x51504,  0x51505,  
0x51510,  0x51511,  0x51514,  0x51515,  
0x51540,  0x51541,  0x51544,  0x51545,  
0x51550,  0x51551,  0x51554,  0x51555,  
0x54000,  0x54001,  0x54004,  0x54005,  
0x54010,  0x54011,  0x54014,  0x54015,  
0x54040,  0x54041,  0x54044,  0x54045,  
0x54050,  0x54051,  0x54054,  0x54055,  
0x54100,  0x54101,  0x54104,  0x54105,  
0x54110,  0x54111,  0x54114,  0x54115,  
0x54140,  0x54141,  0x54144,  0x54145,  
0x54150,  0x54151,  0x54154,  0x54155,  
0x54400,  0x54401,  0x54404,  0x54405,  
0x54410,  0x54411,  0x54414,  0x54415,  
0x54440,  0x54441,  0x54444,  0x54445,  
0x54450,  0x54451,  0x54454,  0x54455,  
0x54500,  0x54501,  0x54504,  0x54505,  
0x54510,  0x54511,  0x54514,  0x54515,  
0x54540,  0x54541,  0x54544,  0x54545,  
0x54550,  0x54551,  0x54554,  0x54555,  
0x55000,  0x55001,  0x55004,  0x55005,  
0x55010,  0x55011,  0x55014,  0x55015,  
0x55040,  0x55041,  0x55044,  0x55045,  
0x55050,  0x55051,  0x55054,  0x55055,  
0x55100,  0x55101,  0x55104,  0x55105,  
0x55110,  0x55111,  0x55114,  0x55115,  
0x55140,  0x55141,  0x55144,  0x55145,  
0x55150,  0x55151,  0x55154,  0x55155,  
0x55400,  0x55401,  0x55404,  0x55405,  
0x55410,  0x55411,  0x55414,  0x55415,  
0x55440,  0x55441,  0x55444,  0x55445,  
0x55450,  0x55451,  0x55454,  0x55455,  
0x55500,  0x55501,  0x55504,  0x55505,  
0x55510,  0x55511,  0x55514,  0x55515,  
0x55540,  0x55541,  0x55544,  0x55545,  
0x55550,  0x55551,  0x55554,  0x55555,  
};

#endif // _TWIDTABS_
